﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.Model;
using HZ.MBSM.DBUtility;
using System.Text;

public partial class Bidder_LookLimitPrice : System.Web.UI.Page
{
    Int32 LLPprjid;
    String LLPstrConditions;
    public String LLPStatus;
    Int64 LLPAccountid_TBR;
    protected void Page_Load(object sender, EventArgs e)
    {

        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        //_AccountType.Add(HZ.MBSM.DAL.AccountType.enumCompany);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAdmin);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            LLPprjid = Int32.Parse(SysFun.IsSQL(Request.QueryString["projectid"]));
            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
            LLPAccountid_TBR = _Account.AccountId;
            Db db = new Db();
            string sql = "select * From ProjectCompanyAttribution where AccountId='" + LLPAccountid_TBR.ToString() + "' and ProjectId=" + LLPprjid.ToString();
            if (db.DataTable(sql).Rows.Count > 0)
            {
                db.Close();
                showGridView();
            }
            else
            {
                Response.Write("<script>window.alert('！您不能查看限价！');</script>");
                Response.Write("<script>window.location=\"Nothing.aspx?Projectid=" + LLPprjid.ToString() + "\"</script>");
            }
        }
    }


    /// <summary>
    /// 查询总共有多少页
    /// </summary>
    /// <returns></returns>
    /// <summary>
    /// 将数据绑定到GridView1
    /// </summary>
    /// <param name="PageIndex">转向第几页</param>
    public void showGridView()
    {
        LLPstrConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "bidprice";                                               //要查询的表明
        dbPage.Key = "Bidid";                                               //表的主键    
        dbPage.Where = LLPstrConditions;                                           //查询条件    
        dbPage.SelectField = " ProductCode,Goodsid,productname,outlookc,QualityLevels,Medicinemodel,ScName,factor,Convert(Numeric(20,2),LimitPrice*factor) as LimitPricePack,Convert(Numeric(20,4),LimitPrice) as LimitPriceMin";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 15;                                                    //没有显示记录条数   
        dbPage.OrderBy = "ProductName,Medicinemodel,Outlookc,Bidid";                  //排序字段
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        GridView1.DataSource = dr;
        GridView1.DataBind();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键
    }

    public string fctConditions()
    {
        string strtemp;
        string PN = SysFun.ToTrim(ProductName.Text);
        string BPGoodsid = txtGoodsId.Text.Trim();
        string LLPCode = txtProductCode.Text.Trim();

        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        if (_Account != null)
        {
            LLPAccountid_TBR = SysFun.ToLong(_Account.AccountId);
            strtemp = " AccountID_TB='" + LLPAccountid_TBR.ToString() + "' and CheckStatus='1' And ProjectId=" + LLPprjid.ToString() + " And";
            if (PN != "")
            {
                strtemp += " productname like '%" + PN + "%' And";
            }
            if (BPGoodsid != "")
            {
                strtemp += " Goodsid ='" + BPGoodsid + "' And";
            }
            if (LLPCode != "")
            {
                strtemp += " ProductCode like '%" + LLPCode + "%' And";
            }
            if (strtemp != "")
            {
                strtemp = "  " + strtemp.Substring(0, strtemp.Length - 3);
            }
        }
        else
        {
            strtemp = "";

        }
        return strtemp;


    }
}
